/*
 * @Author: EltonLi lijiaming@uavi-tech.com
 * @Date: 2023-09-07 13:59:21
 * @LastEditors: EltonLi lijiaming@uavi-tech.com
 * @LastEditTime: 2023-09-07 15:40:50
 * @FilePath: \zino-fc-v4\ZINO\sensor\spl06\spl0601.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-09-07     UAVI02       the first version
 */
#ifndef __SPL0601_H__
#define __SPL0601_H__

#include <rtdef.h>
#include <sensor.h>

#define SPL06_I2C_ADDR (0x76)
#define SPL06_DEFAULT_CHIP_ID (0x10)
#define SPL06_READ_REG (0x80)
#define SPL06_PRESSURE_MSB_REG (0x00)      /* Pressure MSB Register */
#define SPL06_PRESSURE_LSB_REG (0x01)      /* Pressure LSB Register */
#define SPL06_PRESSURE_XLSB_REG (0x02)     /* Pressure XLSB Register */
#define SPL06_TEMPERATURE_MSB_REG (0x03)   /* Temperature MSB Reg */
#define SPL06_TEMPERATURE_LSB_REG (0x04)   /* Temperature LSB Reg */
#define SPL06_TEMPERATURE_XLSB_REG (0x05)  /* Temperature XLSB Reg */
#define SPL06_PRESSURE_CFG_REG (0x06)      /* Pressure configuration Reg */
#define SPL06_TEMPERATURE_CFG_REG (0x07)   /* Temperature configuration Reg */
#define SPL06_MODE_CFG_REG (0x08)          /* Mode and Status Configuration */
#define SPL06_INT_FIFO_CFG_REG (0x09)      /* Interrupt and FIFO Configuration */
#define SPL06_INT_STATUS_REG (0x0A)        /* Interrupt Status Reg */
#define SPL06_FIFO_STATUS_REG (0x0B)       /* FIFO Status Reg */
#define SPL06_RST_REG (0x0C)               /* Softreset Register */
#define SPL06_CHIP_ID_REG (0x0D)           /* Chip ID Register */
#define SPL06_COEFFICIENT_CALIB_REG (0x10) /* Coeffcient calibraion Register */

#define SPL06_CALIB_COEFFICIENT_LENGTH (18)
#define SPL06_DATA_FRAME_SIZE (6)

#define SPL06_CONTINUOUS_MODE (0x07)

#define TEMPERATURE_INTERNAL_SENSOR (0)
#define TEMPERATURE_EXTERNAL_SENSOR (1)

// 测量次数 times / S
#define SPL06_MWASURE_1 (0x00)
#define SPL06_MWASURE_2 (0x01)
#define SPL06_MWASURE_4 (0x02)
#define SPL06_MWASURE_8 (0x03)
#define SPL06_MWASURE_16 (0x04)
#define SPL06_MWASURE_32 (0x05)
#define SPL06_MWASURE_64 (0x06)
#define SPL06_MWASURE_128 (0x07)

// 过采样率
#define SPL06_OVERSAMP_1 (0x00)
#define SPL06_OVERSAMP_2 (0x01)
#define SPL06_OVERSAMP_4 (0x02)
#define SPL06_OVERSAMP_8 (0x03)
#define SPL06_OVERSAMP_16 (0x04)
#define SPL06_OVERSAMP_32 (0x05)
#define SPL06_OVERSAMP_64 (0x06)
#define SPL06_OVERSAMP_128 (0x07)

#define SPL06_RESET_EMPTY_FIFO 0X80 /**After reading out all data from the FIFO, write '1' to clear \
all old data */
#define SPL06_SOFT_RESET 0X09       /**Write '1001' to generate a soft reset. A soft reset will run \
       through the same sequences as in power-on reset. */

struct spl0601_calib_param_t
{
    rt_int16_t c0;
    rt_int16_t c1;
    rt_int32_t c00;
    rt_int32_t c10;
    rt_int16_t c01;
    rt_int16_t c11;
    rt_int16_t c20;
    rt_int16_t c21;
    rt_int16_t c30;
};

typedef struct
{
    struct spl0601_calib_param_t calib_param;
    struct rt_spi_device *spi_dev;
    rt_uint8_t dev_name[8];
    rt_uint8_t dev_id;
    rt_int32_t rawPressure;
    rt_int32_t rawTemperature;
    rt_int32_t kP;
    rt_int32_t kT;
    rt_int32_t BaroAltitude;
} spl0601_device_t;

#endif /* ZINO_SENSOR_SPL06_SPL0601_H_ */
